package com.gitee.wsl.unit.angle.ext

import androidx.compose.ui.geometry.Offset
import com.gitee.wsl.math.Math
import com.gitee.wsl.unit.angle.AngleUnit
import com.gitee.wsl.unit.angle.toRadians
import kotlin.math.atan2

//座标点
fun AngleUnit.calcX(cx: Float, radius: Float) = cx + radius * cos()

fun AngleUnit.calcY(cy: Float, radius: Float)= cy + radius * sin()

fun AngleUnit.getPoint(center: Offset, radius: Float) = Offset(calcX(center.x,radius).toFloat(),calcY(center.y,radius).toFloat())

/**
 * Obtains an angle from rectangular coordinates.
 *
 * @param x the abscissa coordinate.
 * @param y the ordinate coordinate.
 *
 * @return a new angle, whose size is determined from `x` and `y`.
 */
fun AngleUnit.Companion.fromXY(x: Double, y: Double) = atan2(y, x).toRadians()

fun AngleUnit.Companion.between(x0: Float, y0: Float, x1: Float, y1: Float): AngleUnit {
    val angle = atan2(y1 - y0, x1 - x0)
    return if (angle < 0) AngleUnit.Radians(angle + Math.TWO_PI) else AngleUnit.Radians(angle)
}

